import 'package:built_collection/built_collection.dart';
import 'package:mobile_app.core/core/domain/entities/dialect.dart';
import 'package:mobile_app.core/core/domain/entities/tts_voice.dart';

abstract class IsTtsVoiceAvailable {
  bool call({
    required TtsVoice voice,
    required BuiltList<TtsVoice> availableAmVoices,
    required BuiltList<TtsVoice> availableBrVoices,
  });
}

class IsTtsVoiceAvailableImpl implements IsTtsVoiceAvailable {
  const IsTtsVoiceAvailableImpl();

  @override
  bool call({
    required TtsVoice voice,
    required BuiltList<TtsVoice> availableAmVoices,
    required BuiltList<TtsVoice> availableBrVoices,
  }) {
    late final BuiltList<TtsVoice> availableVoices;

    if (voice.dialect == Dialect.am) {
      availableVoices = availableAmVoices;
    } else if (voice.dialect == Dialect.br) {
      availableVoices = availableBrVoices;
    }

    for (final availableVoice in availableVoices) {
      if (availableVoice == voice) {
        return true;
      }
    }

    return false;
  }
}
